# ifndef __FileWriter_H_
# define __FileWriter_H_

class CFileWriter {
	// Disable copy semantics.
	CFileWriter (const CFileWriter &);
	void operator = (const CFileWriter &);

  public:
	CFileWriter (HANDLE _hFile);
	~CFileWriter () {delete [] m_pBuffer;}

	void SetPos (size_t _cPos);

	void FlushBuffer ();

	void WriteBin (size_t _cLen, BYTE _bt = 0);
	void WriteBin (const void * _pData, size_t _cLen);
	template<typename T>
	void WriteBin (const T & _data) {WriteBin (& _data, sizeof (T));}

	void WriteBYTE  (BYTE _bt)  {WriteBin (& _bt, sizeof (BYTE));}
	void WriteWORD  (WORD _w)   {WriteBin (& _w,  sizeof (WORD));}
	void WriteDWORD (DWORD _dw) {WriteBin (& _dw, sizeof (DWORD));}

	void WriteS (const char * _str, size_t _cLen);
	void WriteS (const char * _str) {WriteS (_str, ::strlen (_str));}
	void WriteS (const string_t & _str) {WriteS (_str.c_str (), _str.size ());}
	void __cdecl WriteFmt (const char * _strFormat, ...);

	void WriteC (char _c) {WriteS (& _c, 1);}
	void WriteU (unsigned _u);
	void WriteX (unsigned _x);
	void WriteF (float _f);
	void WriteDF (double _f);

	size_t GetPos () const {return m_cPos;}
	size_t GetLine () const {return m_cLine;}
	bool GetOverflow () const {return m_bOverflow;}

	void SetFPrecision (size_t _cPrecOrder);

  private:
	void _WriteFraction (float _f);
	void _WriteFractionD (double _f);

	const HANDLE m_hFile;

	// Buffer data.
	char * m_pBuffer;
	size_t m_cBufferPosition;

	// Cursor data.
	size_t m_cPos;
	size_t m_cLine;
	bool   m_bOverflow;

	// Floating-point precision control.
	size_t m_cPrecOrder;
	float  m_fPrecFactor;
};

# endif // __FileWriter_H_